package avicit.im.lantop.basic.fieldmapset.action.rest;


import avicit.cbb.techclass.billdefine.action.rest.BillDefineManagerRest;
import avicit.cbb.techclass.tabledefine.commtablemanager.domain.CbbTabColumns;
import avicit.im.lantop.basic.fieldmapset.action.service.LantopFieldMapSetService;
import avicit.im.lantop.basic.fieldmapset.domain.LantopFieldRelateSet;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：jiam
 * @邮箱：jiam@avic-digital.com
 * @创建时间： 2020-12-31 14:52
 * @类说明：oa_travel_rbRest
 * @修改记录：
 */

@RestController
@Api(tags = "LantopFieldMapSetService", description = "LantopFieldMapSetService")
@RequestMapping("/api/avicit/im/lantop/basic/fieldmapset/action/rest/LantopFieldMapSetServiceRest")
public class LantopFieldMapSetServiceRest {


    private static final Logger LOGGER = LoggerFactory.getLogger(LantopFieldMapSetServiceRest.class);


    @Resource
    LantopFieldMapSetService lantopFieldMapSetService;


    /**
     * 获取选择库表树NODES
     * @param map
     * @return
     */
    @PostMapping("/selectTableFindTreeNodesByParentId")
    @ApiOperation(value = "获取选择库表树NODES")
    public ResponseMsg<List<TreeNode>> selectTableFindTreeNodesByParentId(@ApiParam(value = "获取选择库表树NODES", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<TreeNode>> responseMsg = new ResponseMsg<>();
        List<TreeNode> root = null;
        try {
            String type = (String) map.get("type");
            String flag = (String) map.get("flag");
            String sOrt = (String) map.get("sOrt");
            String orgId = (String) map.get("orgId");
            root = lantopFieldMapSetService.selectTableFindTreeNodesByParentId("ROOT", type, flag, sOrt, orgId);
            responseMsg.setResponseBody(root);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 获取公共字段信息
     * @param map
     * @return
     */
    @PostMapping("/getPublicFieldInfo")
    @ApiOperation(value = "基本字段查询对象")
    public ResponseMsg<List<Map<String, Object>>> getPublicFieldInfo(@ApiParam(value = "基本字段查询对象", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> publicFieldInfo = lantopFieldMapSetService.getPublicFieldInfo();
            responseMsg.setResponseBody(publicFieldInfo);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 获取字段对应设置数据
     * @param map
     * @return
     */
    @PostMapping("/getPageRelateSetList")
    @ApiOperation(value = "获取字段对应设置数据")
    public ResponseMsg<Page<Map<String, Object>>> getPageRelateSetList(@ApiParam(value = "获取字段对应设置数据", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<Page<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Paging<LantopFieldRelateSet> page = (Paging<LantopFieldRelateSet>) map.get("page");
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            Page<Map<String, Object>> pageRelateSetList = lantopFieldMapSetService.getPageRelateSetList(page, parameter);
            responseMsg.setResponseBody(pageRelateSetList);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 删除字段对应设置
     * @param ids
     * @return
     */
    @PostMapping("/deleteMapSet")
    @ApiOperation(value = "删除字段对应设置")
    public ResponseMsg<Page<Map<String, Object>>> deleteMapSet(@ApiParam(value = "删除字段对应设置", name = "ids") @RequestBody String ids) {
        ResponseMsg<Page<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            lantopFieldMapSetService.deleteMapSet(ids);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }
}
